<?php
declare (strict_types = 1);

namespace app\admin\controller;
use app\admin\middleware\Auth;
use app\model\BannersModel;
use app\model\InnerTestConfigModel;
use app\model\InnerTestUserModel;
use app\model\RedisModel;
use think\App;
use think\facade\Db;

class InnerTestUser extends Base {

    protected $middleware = [Auth::class];
    private $innerTestUserModel;
    private $req;

    private $page;

    private $limit;



    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->innerTestUserModel = new InnerTestUserModel();

        $this->req =  request()->param();

        $this->page = isset($this->req['page']) ? $this->req['page'] : 1;

        $this->limit = isset($this->req['limit']) ? $this->req['limit'] : 20;

        $this->isLogin();
    }



    public function getList()
    {
        $list = $this->innerTestUserModel->getList([],$this->page,$this->limit,"updated_at","DESC");

        $total = $this->innerTestUserModel->getTotal();

        $this->succData($total,$list);
    }





    /*
     * 关闭
     * */
    public function updateStatus(){

        if(!isset($this->req['id']) || empty($this->req['id'])){
            return $this->fail("请选择操作的数据");
        }

        if(!isset($this->req['accept_status']) || !in_array($this->req['accept_status'],[1,-1])){
            return $this->fail("请选择通过或则拒绝");
        }

        if($this->innerTestUserModel->getTotal([
            "id"=>$this->req['id'],
            "accept_status"=>$this->req['accept_status'],
            ]) > 0){
            return $this->fail("重复操作");
        }

        $res = $this->innerTestUserModel->updateOne($this->req['id'],[
            "accept_status"=>$this->req['accept_status'],
            "refuse_time"=>date("Y-m-d H:i:s"),
        ]);


        if($res){
            return $this->succ();
        }else{
            return $this->fail();
        }

    }



    /*
  * 关闭
  * */
    public function del(){

        if(!isset($this->req['id']) || empty($this->req['id'])){
            return $this->fail("请选择操作的数据");
        }

        if( $this->innerTestUserModel->where(["id"=>$this->req['id']])->delete()){
            return $this->succ();
        }else{
            return $this->fail();
        }

    }

}
